package test;

import java.util.Scanner;

public class bbb {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        //在此输入您的代码...
        int x=scan.nextInt();
        int n=x,t=0;
        while(x>0){
            t++;
            x=x/2;
        }
        System.out.println((int)Math.pow(2,t)-n);
        scan.close();
    }
}
